package com.hibernate.database;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

/**
 * 
 */

/**
 * @author ysitu
 *
 */
public class CreateOneToOneTables {
	private static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
	private static String database = "jdbc:derby:derbyDB";
	
	public static void main(String[] args) {
		try {
			Class.forName(driver);
			Properties prop = new Properties();
			prop.put("user", "user1");
			prop.put("password", "user1");
			Connection conn = DriverManager.getConnection(database,prop);
			conn.setAutoCommit(false);
			Statement stat = conn.createStatement();
			System.out.println("Create One-to-One table start!");
			stat.execute("create table Person(person_id int, person_name varchar(80),primary key(person_id))");
			stat.execute("create table Card_FK(card_id int, card_number varchar(80),person_id int, primary key(card_id), foreign key (person_id) references Person(person_id))");
//			stat.execute("create table Card_PK(card_id int, card_number varchar(80), primary key(card_id), foreign key (card_id) references Person(person_id))");
			System.out.println("Create One-to-One table end!");
//			PreparedStatement ps = conn.prepareStatement("insert into book values(?,?,?)");
			conn.commit();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
